package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjshopcar;
import com.chezhujie.www.persistence.CzjshopcarMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 购物车
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjshopcarService extends BaseService<Czjshopcar> {
    @Autowired
    private CzjshopcarMapper czjshopcarMapper;

    @Autowired
    public void setBaseMapper(CzjshopcarMapper czjshopcarMapper) {
        this.baseMapper = czjshopcarMapper;
    }

    public List<Map<String,Object>> getListUserId(Map<String, Object> param) {
        return czjshopcarMapper.listUserId(param);
    }
    public List<Map<String,Object>> getListCommodityId(Map<String, Object> param) {
        return czjshopcarMapper.listCommodityId(param);
    }
    public List<Map<String,Object>> getListBusinessId(Map<String, Object> param) {
        return czjshopcarMapper.listBusinessId(param);
    }

    public void checkEntity(Czjshopcar czjshopcar) throws ClassCheckException {
        if(czjshopcar.getShopcarId()!=null&&czjshopcar.getShopcarId().length()>19){
            throw new ClassCheckException("购物车主键不能超过19个字符");
        }
        if(czjshopcar.getCommodityId()!=null&&czjshopcar.getCommodityId().length()>19){
            throw new ClassCheckException("购物车商品不能超过19个字符");
        }
        if(czjshopcar.getBusinessId()!=null&&czjshopcar.getBusinessId().length()>19){
            throw new ClassCheckException("购物车商家不能超过19个字符");
        }
        if(czjshopcar.getContent()!=null&&czjshopcar.getContent().length()>255){
            throw new ClassCheckException("购物车内容不能超过255个字符");
        }
    }
    public void checkListEntity(List<Czjshopcar> listCzjshopcar) throws ClassCheckException {

        for (Czjshopcar czjshopcar : listCzjshopcar) {
            checkEntity(czjshopcar);
        }

    }
}
